package cn.rdq.iknesssystem.service.impl;

import cn.hutool.core.util.ObjectUtil;
import cn.rdq.api.po.User;
import cn.rdq.api.vo.UserVo;
import cn.rdq.dao.UserMapper;
import cn.rdq.iknesssystem.service.UserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Override
    public List<User> queryUsers(UserVo userVo) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        if (StringUtils.isNotEmpty(userVo.getUsername())) {
            wrapper.like("username", userVo.getUsername());
        }
        if (StringUtils.isNotEmpty(userVo.getEmail())) {
            wrapper.eq("email", userVo.getEmail());
        }
        if (ObjectUtil.isNotEmpty(userVo.getId())) {
            wrapper.eq("id", userVo.getId());
        }
        PageHelper.startPage(userVo.getCurrentPage(), userVo.getPageSize());
        return list(wrapper);
    }

    @Override
    public void delete(Long id) {
        removeById(id);
    }
}
